`timescale 1ns / 1ps
module a4(
    input        cin,          
    input  [3:0] a,            
    input  [3:0] b,            
    output       cout,   
    output [3:0] sum
);


wire [3:0] P, G;
assign P = a ^ b;
assign G = a & b;


wire [3:0] C;
assign C[0] = cin;                                
assign C[1] = G[0] | (P[0] & C[0]);
assign C[2] = G[1] | (P[1] & G[0]) | (P[1] & P[0] & C[0]);
assign C[3] = G[2] | (P[2] & G[1]) | (P[2] & P[1] & G[0]) |
              (P[2] & P[1] & P[0] & C[0]);

assign cout = G[3] | (P[3] & G[2]) | (P[3] & P[2] & G[1]) |
              (P[3] & P[2] & P[1] & G[0]) |
              (P[3] & P[2] & P[1] & P[0] & C[0]);


assign sum = P ^ {C[3], C[2], C[1], C[0]};

endmodule